package com.openbravo.data.model;

public class Table
{
  private String name;
  private Column[] columns;

  public Table(String paramString, Column[] paramArrayOfColumn)
  {
    this.name = paramString;
    this.columns = paramArrayOfColumn;
  }

  public String getName()
  {
    return this.name;
  }

  public Column[] getColumns()
  {
    return this.columns;
  }

  public String getListSQL()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("select ");
    for (int i = 0; i < this.columns.length; i++)
    {
      if (i > 0)
        localStringBuffer.append(", ");
      localStringBuffer.append(this.columns[i].getName());
    }
    localStringBuffer.append(" from ");
    localStringBuffer.append(this.name);
    return localStringBuffer.toString();
  }

  public String getInsertSQL()
  {
    StringBuffer localStringBuffer1 = new StringBuffer();
    StringBuffer localStringBuffer2 = new StringBuffer();
    localStringBuffer1.append("insert into ");
    localStringBuffer1.append(this.name);
    localStringBuffer1.append(" (");
    for (int i = 0; i < this.columns.length; i++)
    {
      if (i > 0)
      {
        localStringBuffer1.append(", ");
        localStringBuffer2.append(", ");
      }
      localStringBuffer1.append(this.columns[i].getName());
      localStringBuffer2.append("?");
    }
    localStringBuffer1.append(") values (");
    localStringBuffer1.append(localStringBuffer2.toString());
    localStringBuffer1.append(")");
    return localStringBuffer1.toString();
  }

  public String getUpdateSQL()
  {
    StringBuffer localStringBuffer1 = new StringBuffer();
    StringBuffer localStringBuffer2 = new StringBuffer();
    for (int i = 0; i < this.columns.length; i++)
      if (this.columns[i].isPK())
      {
        if (localStringBuffer2.length() == 0)
          localStringBuffer2.append(" where ");
        else
          localStringBuffer2.append(" and ");
        localStringBuffer2.append(this.columns[i].getName());
        localStringBuffer2.append(" = ?");
      }
      else
      {
        if (localStringBuffer1.length() > 0)
          localStringBuffer1.append(", ");
        localStringBuffer1.append(this.columns[i].getName());
        localStringBuffer1.append(" = ?");
      }
    return "update " + this.name + " set " + localStringBuffer1 + localStringBuffer2;
  }

  public String getDeleteSQL()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < this.columns.length; i++)
    {
      if (!this.columns[i].isPK())
        continue;
      if (localStringBuffer.length() == 0)
        localStringBuffer.append(" where ");
      else
        localStringBuffer.append(" and ");
      localStringBuffer.append(this.columns[i].getName());
      localStringBuffer.append(" = ?");
    }
    return "delete from " + this.name + localStringBuffer;
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.model.Table
 * JD-Core Version:    0.6.0
 */